$(function() {
	var ready = {device : false}

	$('#btn_alarm_myteam').on('change',function() {//알람기능 on (default off)
		//console.log('hihi');
		if($(this).val() == 'on'){
			var alarm_data = $('.main_date').text();
			var alarm_date = alarm_data.substring(0,2);
			var strArray = alarm_data.split(':');
			var alarm_min  = strArray[1];
			var alarm_hour = strArray[0].substring(strArray[0].length-2);

			localStorage.setItem('alarm_date', alarm_date);
			localStorage.setItem('alarm_hour', alarm_hour);
			localStorage.setItem('alarm_min', alarm_min);
					
			
			getLocalMyteam_alarm();
		
			//alarm_date = ifZero(alarm_date);
			
		}
	});
	
	function getLocalMyteam_alarm(){
		alarm_date = localStorage.getItem('alarm_date');
		alarm_hour = localStorage.getItem('alarm_hour');
		alarm_min = localStorage.getItem('alarm_min');
		alarmSet(alarm_date, alarm_hour, alarm_min);//경기시간
	}

	function alarmSet(d, h, m){
		//디바이스가 ready되면 울려
		var now = new Date();
		d = 12;
		h = 15;
		m = 52;
		var set_Time = new Date(new Date(now.getFullYear(), now.getMonth(), d, h, m).getTime() - 30*1000);//조작된 경기 시간

		console.log("받아오는 경기 시간 date: " + d + " hour : " + h + " min :" + m);
		console.log("경기 세팅 시간(경기시간 30초전 알람) :" + set_Time);
		ready.device = true;
		
		if(ready.device){
			plugins.localNotification.add({					 
			     date : set_Time,
			     message : "Phonegap - Local Notification\r\nSubtitle comes after linebreak",
			     ticker : "This is a sample ticker text",
			     repeatDaily : false,
			     id : 1,
			     icon : 'spoclock_icon',
			     url : 'file:///android_asset/www/alarmNotify.html'
			 });
		}
	}
});

